var test = require('tape')
var pdf = require('../../')
var path = require('path')
var fs = require('fs')

test('allows custom html and css', function (t) {
  t.plan(3)

  var template = path.join(__dirname, 'Title.html')
  var filename = template.replace('.html', '.pdf')
  var templateHtml = fs.readFileSync(template, 'utf8')

  // var image = path.join('file://', __dirname, 'image.png')
  // templateHtml = templateHtml.replace('{{image}}', image)

  var options = {

    // "height": "10.5in",        // allowed units: mm, cm, in, px
    // "width": "8in",            // allowed units: mm, cm, in, px


    "height": "310mm",        // allowed units: mm, cm, in, px
    "width": "229mm",            // allowed units: mm, cm, in, px

    // "format": "A4",        // allowed units: A3, A4, A5, Legal, Letter, Tabloid
    // "orientation": "portrait", // portrait or landscape

    // "type": "pdf",
    // "zoomFactor": "0.8",
    // "border": {
    //   "top": "2mm",            // default is 0, units: mm, cm, in, px
    //   "right": "10mm",
    //   "bottom": "2mm",
    //   "left": "3.5mm"
    // },
    // paginationOffset: 1,
    // "header": {
    //   "height": "45mm",
    //   "contents": '<div style="text-align: center;">Author: Marc Bachmann</div>'
    // },
    // "footer": {
    //   "height": "28mm",
    //   "contents": {
    //     first: 'Cover page',
    //     2: 'Second page', // Any page number is working. 1-based index
    //     default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>', // fallback value
    //     last: 'Last Page'
    //   }
    // },
  }

  pdf
  .create(templateHtml, options)
  .toFile(filename, function (err, pdf) {
    t.error(err)
    t.assert(pdf.filename, 'Returns the filename')
    t.assert(fs.existsSync(pdf.filename), 'Saves the file to the desired destination')
  })
})
